using System;
using System.Collections.Generic;
using System.Text;

using FarseerGames.FarseerPhysics;
using FarseerGames.FarseerPhysics.Dynamics;
using FarseerGames.FarseerPhysics.Collisions;
using FarseerGames.FarseerPhysics.Factories;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;


namespace GrapplingHookGameData
{
    public class PhysicsObject:GameObject
    {
        protected PhysicsSimulator physicsSimulator;

        public bool CreateBody { get; set; }
        public bool CreateGeom { get; set; }

        public new Vector2 Position
        {
            get { return Body.Position; }
            set { Body.Position = value; }
        }

        public new float Rotation
        {
            get { return Body.Rotation; }
            set { Body.Rotation = value; }
        }

        public Body Body { get; protected set; }

        public Geom Geom { get; protected set; }

        public PhysicsObject(IGameDataCallbacks gameCallback, Vector2 startPosition, string textureName)
            : base(gameCallback, startPosition, textureName)
        {
            CreateBody = false;
            CreateGeom = false;
        }

        public PhysicsObject(IGameDataCallbacks gameCallback, Vector2 startPosition, float width, float height, string textureOrSpritesheetName, bool useSpriteSheet)
            : base(gameCallback, startPosition, width, height, textureOrSpritesheetName, useSpriteSheet)
        {
        }

        public virtual void LoadContent(ContentManager content, PhysicsSimulator physicsSimulator)
        {   
            base.LoadContent(content);
            this.physicsSimulator = physicsSimulator;
            if (CreateBody)
            {
                Body = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, Width, Height, 1);
                if (CreateGeom)
                {
                    Geom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, Body, Width, Height);
                }
            }
        }

        public override void Update(GameTime gameTime, bool isHost)
        {
            position = Body.Position;
            rotation = Body.Rotation;
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);
        }
   }
}
